package com.example.chengww.myone.fragment;


import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.example.chengww.myone.R;
import com.example.chengww.myone.activity.MainActivity;

/**
 * A simple {@link Fragment} subclass.
 */
public class MovieFragment extends LazyFragment {

    private Button button;
    // 标志位，标志已经初始化完成。
    private boolean isPrepared;

    public MovieFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_movie, container, false);
        button = (Button) view.findViewById(R.id.button);
        isPrepared = true;
        lazyLoad();
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences mSharedPreferences = ((MainActivity)getActivity()).getSharedPreferences("isFirstEntry",
                        Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = mSharedPreferences.edit();
                editor.putBoolean("isGuide",true);
                editor.commit();
                Toast.makeText(getActivity(),"下次进入应用将再次进入引导页",
                        Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    protected void lazyLoad() {
        if(!isPrepared || !isVisible) {
            return;
        }
        //填充各控件的数据

    }
}
